import 'package:flutter/material.dart';
import 'package:local_coffee/components/c_button/index.dart';
import 'package:local_coffee/components/rgba.dart';
import 'package:local_coffee/components/hex.dart';
import 'package:local_coffee/routes/index.dart';
import 'package:local_coffee/utils/global.dart';

class OrderListRow extends StatelessWidget {
  
  final int orderStatus;
  final String address;
  final String goodsName;
  final String orderNum;
  final String time;
  final double price;
  final Function onPress;

  /// 创建订单列表信息
  /// ```
  /// @param {int} orderStatus - 订单状态 1: 待付款 2: 已完成 3: 已取消
  /// @param {String} address - 地址
  /// @param {String} goodsName - 商品名字
  /// @param {String} orderNum - 订单号
  /// @param {String} time - 订单时间
  /// @param {double} price - 价格
  /// ```
  OrderListRow(
    this.orderStatus,
    {
      this.address,
      this.goodsName,
      this.orderNum,
      this.time,
      this.price,
      this.onPress
    }
  );

  /// 文字状态
  Widget textStatus() {
    var text = '';
    var color = RGBA.rgbaa6a6a6;
    if (orderStatus == 1) {
      color = RGBA.rgba88afd5;
      text = '待付款';
    } else if (orderStatus == 2) {
      text = '已完成';
    } else if (orderStatus == 3) {
      text = '已取消';
    }
    return Text(
      text,
      style: TextStyle(
        color: color,
        fontSize: 12
      ),
    );
  }

  /// 按钮状态
  List<Widget> buttonStatus(BuildContext context) {
    List<Widget> button = [];

    var btn1 = Container(
      margin: EdgeInsets.only(left: 10),
      child: CButton.normal(
        child: Text(
          '再来一单',
          style: TextStyle(
            fontSize: 12
          ),
        ),
        color: RGBA.rgba383838,
        plain: true,
        height: 28,
        width: 74,
        borderColor: RGBA.rgbaf2f2f2,
        onPressed: () => {}
      ),
    );

    var btn2 = Container(
      margin: EdgeInsets.only(left: 10),
      child: CButton.normal(
        child: Text(
          '去支付',
          style: TextStyle(
            fontSize: 12
          ),
        ),
        color: RGBA.rgbaff8102,
        borderColor: RGBA.rgbaff8102,
        plain: true,
        height: 28,
        width: 74,
        onPressed: () => G.pushNamed(N.orderConfirm)
      ),
    );

    var btn3 = Container(
      margin: EdgeInsets.only(left: 10),
      child: CButton.normal(
        child: Text(
          '去评价',
          style: TextStyle(
            fontSize: 12
          ),
        ),
        color: RGBA.rgba94c4ec,
        borderColor: RGBA.rgba94c4ec,
        plain: true,
        height: 28,
        width: 74,
        onPressed: () => G.pushNamed(N.orderEvaluation)
      ),
    );

    switch (orderStatus) {
      case 1:
        button.add(btn2);
        break;
      case 2:
        button.add(btn1);
        button.add(btn3);
        break;
      case 3:
        button.add(btn1);
        break;
    }

    return button;
  }

  @override 
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => onPress == null ? () {} : onPress(),
      child: Container(
        margin: EdgeInsets.symmetric(vertical: 10),
        padding: EdgeInsets.symmetric(horizontal: 15, vertical: 12),
        height: 160,
        color: HEX.hexfff,
        child: Column(
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(bottom: 10),
              decoration: BoxDecoration(
                border: G.borderBottom()
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    '外卖订单',
                    style: TextStyle(
                      color: RGBA.rgbaa6a6a6,
                      fontSize: 12
                    ),
                  ),
                  textStatus()
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 10),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    '$address...',
                    style: TextStyle(
                      color: RGBA.rgba383838,
                      fontSize: 15,
                      fontWeight: FontWeight.bold
                    ),
                  ),
                  Text(
                    '$time',
                    style: TextStyle(
                      fontSize: 12,
                      color: RGBA.rgbaa6a6a6,
                    ),
                  )
                ],
              ),
            ),
            Row(
              children: <Widget>[
                Text(
                  '$goodsName 等 共 1 件商品',
                  style: TextStyle(
                    color: RGBA.rgba505050,
                    fontSize: 12
                  ),
                )
              ],
            ),
            Container(
              margin: EdgeInsets.only(top: 25),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    '$price',
                    style: TextStyle(
                      color: RGBA.rgba383838,
                      fontSize: 14,
                      fontWeight: FontWeight.bold
                    ),
                  ),
                  Row(
                    children: buttonStatus(context),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}